package cn.dnui_zll731.dnuifood_731zlll.Fragment;

import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;

import java.util.List;

import cn.dnui_zll731.dnuifood_731zlll.Adapter.Fragment_shopAdapter;
import cn.dnui_zll731.dnuifood_731zlll.R;
import cn.dnui_zll731.dnuifood_731zlll.bean.UserCollection;
import cn.dnui_zll731.dnuifood_731zlll.listener.RetrofitListener;
import cn.dnui_zll731.dnuifood_731zlll.model.UserModel;


public class F2_FoodFragment extends BaseFragment implements RetrofitListener<List<UserCollection>> {
    private Fragment_shopAdapter adapter;
    private UserModel userModel;
    private String userId;

    @Override
    protected int initlayout() {
        return R.layout.fragment2_sc_food;
    }
    @Override
    void initViews() {
        userId=getUser_id();
        recyclerView = view.findViewById(R.id.rv_sc_food);
    }

    @Override
    void initData() {
        userModel = new UserModel();
        userModel.getAllUserCollection(getUser_id(),"1",this);
    }

    @Override
    void initEvents() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(
                getActivity(),
                LinearLayoutManager.VERTICAL,
                false
        );//布局效果---垂直布局
        recyclerView.setLayoutManager(linearLayoutManager);//设置效果
        recyclerView.setItemAnimator(new DefaultItemAnimator());//设置动画效果
    }


    @Override
    public void onSuccess(List<UserCollection> object, int flag) {

        adapter = new Fragment_shopAdapter(getActivity(),object,R.layout.sc_food_item,userId);
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void onFalure() {
        showToast("网络错误");
    }
}
